<?php 
function ListContents($idP)
{
    global $dbsql,$language;
    $listid     = ListIdCatChild($idP);
    $listid     = implode(',',$listid);
    
    $sql_where  = " from tblcontent where cLanguage='$language' and iStatus=1 ";
    if($idP>0)
    {
        $sql_where  .= " and iParentId in ($listid)";
    }
    $sql_select = "select count(iId) as count ".$sql_where;
    $result     = $dbsql->query_fetch($sql_select);
    $countall   = $result['count'];
    
    list($lf,$la)= Split_Page($countall);
    
    $sql_select = "select * ".$sql_where." order by iParentId,iOrder limit $lf,$la";
    return $dbsql->load($sql_select);
}

function ListIdCatChild($idP)
{
    global $dbsql,$language;
    $sql_select = "select iId from tblcategory where iParentId='$idP'";
    $rs         = $dbsql->query($sql_select);
    $listid     = array();
    $listid[]   = $idP;
    
    while($result   = $dbsql->fetch_array($rs))
    {
        $listc  = ListIdCatChild($result['iId']);
        $listid = array_merge($listid,$listc);
    }
    return $listid;
    
}

function getUrlCat($idP)
{
    global $dbsql,$language;
    
    $sql_select = "select cUrlString,iParentId from tblcategory where iId=$idP";
    $result     = $dbsql->query_fetch($sql_select);
    if($result['iParentId']>0)
    {
        $urlP   = getUrlCat($result['iParentId']);
    }
    return $urlP.$result['cUrlString'].'/';
}

function ListOthernews($idP,$id)
{
    global $dbsql,$language;
    
    $sql_select = "select * from tblnews_content where iParentId=$idP and iId!=$id and cLanguage='$language' limit 5";
    return $dbsql->load($sql_select);
}
?>